﻿using Lufei_CaterBLL;
using Lufei_CaterModel;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace Lufei_CaterUI
{
    public partial class FrmAddProduct : Form
    {
        public FrmAddProduct()
        {
            InitializeComponent();
        }

        private void FrmAddProduct_Load(object sender, EventArgs e)
        {
            //给类别文本框添加数据
            CategoryBLL bll = new CategoryBLL();
            cmbCategory.DisplayMember = "catName";
            cmbCategory.ValueMember = "catID";
            cmbCategory.DataSource=   bll.GetCategoryInfos();
        }

        private void btnOk_Click(object sender, EventArgs e)
        {
            //把要插入的数据封装成一个对象
            ProductInfo pi = new ProductInfo();
            pi.CatId = Convert.ToInt32(cmbCategory.SelectedValue);
            pi.ProName =txtName.Text;
            pi.ProCost = Convert.ToDecimal(txtCost.Text);
            pi.ProPrice=Convert.ToDecimal(txtPrice.Text);
            pi.Remark=txtRemark.Text;
            pi.DelFlag = 0;
            pi.ProNum=txtNum.Text;
            pi.ProStock=Convert.ToDecimal(txtStock.Text);
            pi.ProUnit = txtUnit.Text;
            pi.ProSpell=txtSpell.Text;

            ProductBLL bll = new ProductBLL();
           bool isInsert=   bll.InsertProduct(pi);

            if (isInsert)
            {
                MessageBox.Show("插入成功");
                this.Close();
            }
            else
            {
                MessageBox.Show("插入失败");
                this.Close();
            }
        }
    }
}
